<?php
define('ABSPATH', dirname(__FILE__) . '/');
ob_implicit_flush(true);
require_once(dirname(__FILE__) . '/../include.all.php');

$func = function($a) {
    $def = new Deferred;
    setTimeout(function() use($def, $a) {
        $r = rand(1, 10);
        if(1 == $r) {
            var_dump('try ok: ' . $r . ' ' . $a);
            $def->callback($a . 'b');
        } else {
            var_dump('try nook: ' . $r . ' ' . $a);
            $def->errback($a . 'b');
        }
    }, 1);
    return $def;
};
$retry_func = createRetryFunction($func, 5);
$def = $retry_func('a');
$def->addCallbacks(function($res) {
    var_dump('all ok: ' . $res);
    return $res;
}, function($res) {
    var_dump('all nook: ' . $res);
    return $res;
});


echo "\nAll Init\n";
Tick::getInstance()->startExecution();
echo "\nAll Ended\n";
